﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Data;

namespace PJ.Business
{
    /// <summary>
    /// OrderedFragmentService class
    /// </summary>
    /// <typeparam name="O">Object to serve type</typeparam>
    /// <typeparam name="OD">Inner data object type</typeparam>
    /// <typeparam name="ODP">Inner data object provider type</typeparam>
    public abstract class OrderedFragmentService<OI, OD, ODP> : EntityFragmentService<OI, OD, ODP>, IOrderedFragmentService, IOrderedFragmentService<OI>
        where OI : class, IOrderedFragment
        where OD : class, IOrderedFragmentData
        where ODP : class, IOrderedFragmentProvider<OD>
    {
        public OrderedFragmentService(ODP dataService)
            : base(dataService)
        {
        }

        public void Up(IOrderedFragment item)
        {            
            item.Order = Up(item.ParentID, item.Order);              
        }

        public void Down(IOrderedFragment item)
        {
            item.Order = Down(item.ParentID, item.Order);                          
        }

        public bool IsFirst(IOrderedFragment item)
        {
            return IsFirst(item.ParentID, item.Order);
        }

        public bool IsLast(IOrderedFragment item)
        {
            return IsLast(item.ParentID, item.Order);
        }

        public double Up(string parentId, double order)
        {
            return DataService.Up(parentId, order);
        }

        public double Down(string parentId, double order)
        {
            return DataService.Down(parentId, order);
        }

        public bool IsFirst(string parentId, double order)
        {
            return DataService.IsFirst(parentId, order);
        }

        public bool IsLast(string parentId, double order)
        {
            return DataService.IsLast(parentId, order);
        }
    }
}
